<template>
  <div class="home">
    <el-container>
      <el-aside :collapse="isCollapse" width="201px">
        <div class="logo">
          <img src="../assets/logo.png" alt="" />
        </div>
        <el-menu
          :default-active="$route.path"
          class="el-menu--demo"
          background-color="#2d3a38"
          text-color="#fff"
          active-text-color="#ffd04b"
          unique-opened
          router
        >
          <el-menu-item index="/">首页</el-menu-item>
          <el-submenu index="1">
            <template slot="title">
              <i class="el-icon-setting"></i>
              <span>文章管理</span>
            </template>
            <el-menu-item index="/home/post_list">文章列表</el-menu-item>
            <el-menu-item index="/home/post_publish">发布文章</el-menu-item>
          </el-submenu>
          <el-submenu index="2">
            <template slot="title">
              <i class="el-icon-circle-plus"></i>
              <span>栏目管理</span>
            </template>
            <el-menu-item index="/home/columnList">
              <i class="el-icon-user"></i>
              <span>栏目列表</span>
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <el-container class="el-container-s">
        <el-header height="80px">
          <i class="el-icon-s-fold"></i>
          <img :src="userinfo.head_img | imgUrl" class="avatar" :size="50" />
          <span class="nickname">欢迎你:{{ userinfo.nickname }}</span>
          <!-- <el-button type="danger">退出</el-button> -->
          <el-dropdown>
            <span class="el-dropdown-link">
              退出<i class="el-icon-arrow-down el-icon--right"></i>
            </span>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item>首页</el-dropdown-item>
              <el-dropdown-item divided>退出登陆</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </el-header>
        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
import { userDetaiAPI } from "../apis/user";
import { getUserId } from "../utils/localData";
export default {
  data() {
    return {
      userinfo: {},
      isCollapse: true,
    };
  },

  async created() {
    const id = getUserId();
    const res = await userDetaiAPI(id);
    this.userinfo = res.data.data;
  },
};
</script>
<style lang="less" scoped>
.el-container {
  height: 100vw;
}
.el-header {
  background-color: #333;
  color: #fff;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  .el-icon-s-fold {
    flex: 1;
    font-size: 40px;
  }
  .avatar {
    width: 60px;
    height: 60px;
    border-radius: 50%;
  }
  .nickname {
    margin: 0 10px;
  }
}

.el-aside {
  background-color: #000;
  color: #fff;
  // overflow: hidden;
  .logo {
    width: 100%;
    background-color: #fff;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 80px;
  }
}
.el-main {
  background-color: #e9eef3;
  color: #333;
}
.el-dropdown-link {
  cursor: pointer;
  color: #409eff;
}
.el-icon-arrow-down {
  font-size: 20px;
  color: #fff;
}
</style>
